package com.suncreate.zhtz.iot.ctrl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.suncreate.zhtz.iot.model.*;
import com.suncreate.zhtz.iot.service.Ocrtable3Service;
import com.suncreate.zhtz.iot.service.Ocrtable4Service;
import com.suncreate.zhtz.iot.service.ScDataService;
import com.suncreate.zhtz.iot.service.ScWarningStrategyService;
import com.suncreate.zhtz.iot.tool.DataDictionary;
import com.suncreate.zhtz.iot.tool.RequestUnit;
import com.suncreate.zhtz.iot.tool.checkDataUnit;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.xml.crypto.Data;
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;

import static java.util.Calendar.HOUR;

@RestController
@Api(tags = "智慧台站-合肥-四创mysql数据服务接口",description = "四创传感器数据接口")
@RequestMapping("/sc")
public class ScDataController {
    @Autowired
    private ScDataService sc_data_service;
    @Autowired
    private ScWarningStrategyService scWarningStrategyService;
    @Autowired
    private Ocrtable3Service ocrtable3Service;
    @Autowired
    private Ocrtable4Service ocrtable4Service;

    @ApiOperation(value = "获取四创传感器信息，返回传感器信息列表,支持按itemkey过滤")
    @RequestMapping(value = "/query/item",method = RequestMethod.POST,produces = "application/json;charset=UTF-8")
    @ApiImplicitParams({
            @ApiImplicitParam(name="obj",value = "{\"itemkey\":\"\"}",paramType ="body",required = true)
    })
    @ResponseBody
    public ResultJson queryItemByKey(@RequestBody JSONObject obj, HttpServletRequest request)  {
        ResultJson result=new ResultJson();
        //空字符串赋值方法
        String itemkey= "new String()";
        //严禁出现魔法常量，变量命名写全
        //集合类型给一个空实例 而不是null，变量命名不规范
        List<ScItemModel> itemList = new LinkedList<>();
        try {
            itemkey = (String) obj.get("itemkey");
            //捕获异常之后啥都不干？？？异常被吃了
        } catch (Exception e) {
            result.setResultErrorMsg(e.getMessage());
            return result;
        }
        try
        {
            itemList = sc_data_service.queryScItemListbyKey(itemkey);
        }
        catch(Exception e)
        {
            result.setResultFlag(-1);
            result.setResultErrorMsg(e.getMessage());
            return result;
        }
        result.setResultFlag(0);
        //HuTool或者Apache的公共类判断对象空或者字符串空，有专门函数
        if(!StringUtils.isEmpty(itemList))
        {
            //到底是错误异常，还是正常信息
            result.setResultErrorMsg("获取数据完毕,总共"+itemList.size()+"条数据");
        }
        else
        {
            result.setResultErrorMsg("获取数据完毕,list为null");
        }
        result.setResult(itemList);
        return result;
    }

    @ApiOperation(value = "获取四创监控主机信息，返回主机信息列表,支持按itemgroupkey和status过滤")
    @RequestMapping(value = "/query/monitorhost",method = RequestMethod.POST,produces = "application/json;charset=UTF-8")
    @ApiImplicitParams({
            @ApiImplicitParam(name="obj",value = "{\"itemgroupkey\":\"\" ,\"status\": 0}",paramType ="body",required = true)
    })
    @ResponseBody
    public ResultJson queryMonitorHostByKeyAndStatus(@RequestBody JSONObject obj, HttpServletRequest request) {
        ResultJson result=new ResultJson();
        String itemgroupkey= "";
        Integer status=DataDictionary.BACK_STATUS.NORMAL;
        List<MonitorHostModel> MonitorList = new LinkedList<>();
        try {
            itemgroupkey = (String) obj.get("itemgroupkey");
        } catch (Exception e) {
            result.setResultErrorMsg(e.getMessage());
            return result;
        }
        try {
            status = (int) obj.get("status");
        } catch (Exception e) {
            result.setResultErrorMsg(e.getMessage());
            return result;
        }
        try
        {
            MonitorList = sc_data_service.queryMonitorHostListbyKeyAndStatus(itemgroupkey,status);
        }
        catch(Exception e)
        {
            result.setResultFlag(DataDictionary.BACK_STATUS.ABNORMAL);
            result.setResultErrorMsg(e.getMessage());
            return result;
        }
        result.setResultFlag(0);
        if(!StringUtils.isEmpty(MonitorList))
        {
            result.setResultErrorMsg("获取数据完毕,总共"+MonitorList.size()+"条数据");
        }
        else
        {
            result.setResultErrorMsg("获取数据完毕,list为null");
        }
        result.setResult(MonitorList);
        return result;
    }

    @ApiOperation(value = "获取首页总体运行态势信息，返回态势检查结果列表")
    @RequestMapping(value = "/query/global_run_situation",method = RequestMethod.POST,produces = "application/json;charset=UTF-8")
    @ApiImplicitParams({
            @ApiImplicitParam(name="obj",value = "",paramType ="body",required = false)
    })
    @ResponseBody
    public ResultJson queryGlobalRunSituation(@RequestBody JSONObject obj, HttpServletRequest request) {
        ResultJson result=new ResultJson();
        List<ScItemModel> simList=sc_data_service.queryScItemListbyKey("");
        List<EmsItemModel> eimList=sc_data_service.queryEmsItemListbyKey("");
        List<GlobalRunSituationModel> list=sc_data_service.queryGlobalRunSituation();
        Date date=new Date();
        java.sql.Timestamp dateSQL = new java.sql.Timestamp(date.getTime());
        int jcCount=0;
        //参考Hutool集合判断是否为空，对象是否为空，工具类
        if(!StringUtils.isEmpty(list))
        {
            //增强For循环
            for(int i=0;i<list.size();i++)
            {
                GlobalRunSituationModel gm=list.get(i);
                gm.setMonitor_time(dateSQL);
                List<SituationToItemModel> stiList=sc_data_service.querySituationToItemListByGlobalKey(gm.getSituation_key());
                //参考Hutool集合判断是否为空，对象是否为空，工具类
                if(stiList!=null&&stiList.size()>0)
                { //增强For循环
                    for(int j=0;j<stiList.size();j++)
                    {
                        SituationToItemModel sm=stiList.get(j);
                        for(int k=0;k<simList.size();k++)
                        {
                            if(sm.getItem_key().equals(simList.get(k).getItem_key()))
                            {
                                if(simList.get(k).getStatus()!=1)
                                {
                                    //2代表什么
                                    gm.setStatus(2);
                                    gm.setScore(gm.getScore()-sm.getScore());
                                    gm.setError_count(gm.getError_count()+1);
                                    String message="";
                                    if(simList.get(k).getStatus()==3)//告警
                                    {
                                        message="当前在告警状态";
                                    }
                                    else if(simList.get(k).getStatus()==4)//故障
                                    {
                                        message="当前在故障状态";
                                    }
                                    else if(simList.get(k).getStatus()==5)//限制
                                    {
                                        message="当前在限制状态";
                                    }
                                    else if(simList.get(k).getStatus()==6)//冻结
                                    {
                                        message="当前在冻结状态";
                                    }
                                    else if(simList.get(k).getStatus()==0)//离线
                                    {
                                        message="当前在离线状态";
                                    }
                                    AbnormalModel am=new AbnormalModel();
                                    am.setItem_key(simList.get(k).getItem_key());
                                    am.setItem_name(simList.get(k).getItem_name());
                                    am.setMessage(simList.get(k).getItem_name()+message);
                                    am.setStatus(simList.get(k).getStatus());
                                    am.setLocation(simList.get(k).getAddress());
                                    am.setItem_type("sc");
                                    gm.getAbnormalList().add(am);
                                }
                            }
                        }
                        for(int k=0;k<eimList.size();k++)
                        {
                            if(sm.getItem_key().equals(eimList.get(k).getItem_key()))
                            {
                                if(eimList.get(k).getStatus()!=1)
                                {
                                    gm.setStatus(2);
                                    gm.setScore(gm.getScore()-sm.getScore());
                                    gm.setError_count(gm.getError_count()+1);
                                    String message="";
                                    if(eimList.get(k).getStatus()==3)//告警
                                    {
                                        message="当前在告警状态";
                                    }
                                    else if(eimList.get(k).getStatus()==4)//故障
                                    {
                                        message="当前在故障状态";
                                    }
                                    else if(eimList.get(k).getStatus()==5)//限制
                                    {
                                        message="当前在限制状态";
                                    }
                                    else if(eimList.get(k).getStatus()==6)//冻结
                                    {
                                        message="当前在冻结状态";
                                    }
                                    else if(eimList.get(k).getStatus()==0)//离线
                                    {
                                        message="当前在离线状态";
                                    }

                                    AbnormalModel am=new AbnormalModel();
                                    am.setItem_key(eimList.get(k).getItem_key());
                                    am.setItem_name(eimList.get(k).getItem_name());
                                    am.setMessage(eimList.get(k).getItem_name()+message);
                                    am.setStatus(eimList.get(k).getStatus());
                                    am.setItemgroup_sn(eimList.get(k).getItemgroup_sn());
                                    am.setItem_type("sw");
                                    gm.getAbnormalList().add(am);
                                }
                            }
                        }
                    }
                }
                if(gm.getScore()<0)
                {
                    gm.setScore(0);
                }
                if(gm.getError_count()>0)
                {

                    gm.setMessage("共检测了"+stiList.size()+"项，发现"+gm.getError_count()+"个问题");
                }
                else
                {
                    gm.setMessage("共检测了"+stiList.size()+"项，检测正常");
                }
                jcCount=stiList.size()+jcCount;
                list.set(i,gm);
            }
        }
        if(list!=null)
        {
            result.setResultErrorMsg("获取数据完毕,总共"+list.size()+"条数据");
        }
        else
        {
            result.setResultErrorMsg("获取数据完毕,list为null");
        }
        GlobalRunSituationResultModel sm=new GlobalRunSituationResultModel();
        sm.setList(list);
        int errorCount=0;
        for(int i=0;i<list.size();i++)
        {
            errorCount=list.get(i).getError_count()+errorCount;
        }
        String resultMessage="共检测了"+jcCount+"项，发现"+errorCount+"个问题";
        sm.setResultMessage(resultMessage);
        result.setResult(sm);
        return result;
    }



    @ApiOperation(value = "根据站点ID获取单站运行态势信息，返回态势检查结果列表,1为桃花导航台，2为泰雷兹雷达站")
    @RequestMapping(value = "/query/signal_run_situation",method = RequestMethod.POST,produces = "application/json;charset=UTF-8")
    @ApiImplicitParams({
            @ApiImplicitParam(name="obj",value = "{\"centerId\": \"1\"}",paramType ="body",required = false)
    })
    @ResponseBody
    public ResultJson querySignalRunSituation(@RequestBody JSONObject obj, HttpServletRequest request) {
        ResultJson result=new ResultJson();
        String  centerId="";
        List<ScItemModel> simList=null;
        List<EmsItemModel> eimList=null;
        try {
            centerId = (String) obj.get("centerId");
        } catch (Exception e) {
            result.setResultErrorMsg("参数centerId需要设置");
            result.setResultFlag(-1);
            return result;
        }
        if(!centerId.equals("1")&&!centerId.equals("2"))
        {
            result.setResultErrorMsg("参数centerId设置错误");
            result.setResultFlag(-1);
            return result;
        }
        if(centerId.equals("1"))
        {
            simList=sc_data_service.queryScItemListbyGroupKey("001");
            eimList=sc_data_service.queryEmsItemListbyGroupId("3fe34ae067c4403e906a08d92a2d56b2");
        }
        else if(centerId.equals("2"))
        {
            simList=sc_data_service.queryScItemListbyGroupKey("002");
            eimList=sc_data_service.queryEmsItemListbyGroupId("a32b55dc413e4d80ac0cf44ea064b3b3");
        }
        List<SignalRunSituationModel> list=sc_data_service.querySignalRunSituation();
        Date date=new Date();
        java.sql.Timestamp dateSQL = new java.sql.Timestamp(date.getTime());
        int jcCount=0;
        if(list!=null&&list.size()>0)
        {
            for(int i=0;i<list.size();i++)
            {
                SignalRunSituationModel sm=list.get(i);
                sm.setMonitor_time(dateSQL);
                List<SituationToItemModel> sti_list=sc_data_service.querySituationToItemListBySignalKey(sm.getSituation_key());
                if(sti_list!=null&&sti_list.size()>0)
                {
                    for(int j=0;j<sti_list.size();j++)
                    {
                        SituationToItemModel sim=sti_list.get(j);
                        for(int k=0;k<simList.size();k++)
                        {
                            if(sim.getItem_key().equals(simList.get(k).getItem_key()))
                            {
                                if(simList.get(k).getStatus()!=1)
                                {
                                    sm.setStatus(2);
                                    sm.setScore(sm.getScore()-sim.getScore());
                                    sm.setError_count(sm.getError_count()+1);
                                    String message="";
                                    if(simList.get(k).getStatus()==3)//告警
                                    {
                                        message="当前在告警状态";
                                    }
                                    else if(simList.get(k).getStatus()==4)//故障
                                    {
                                        message="当前在故障状态";
                                    }
                                    else if(simList.get(k).getStatus()==5)//限制
                                    {
                                        message="当前在限制状态";
                                    }
                                    else if(simList.get(k).getStatus()==6)//冻结
                                    {
                                        message="当前在冻结状态";
                                    }
                                    else if(simList.get(k).getStatus()==0)//离线
                                    {
                                        message="当前在离线状态";
                                    }
                                    AbnormalModel am=new AbnormalModel();
                                    am.setItem_key(simList.get(k).getItem_key());
                                    am.setItem_name(simList.get(k).getItem_name());
                                    am.setMessage(simList.get(k).getItem_name()+message);
                                    am.setStatus(simList.get(k).getStatus());
                                    am.setLocation(simList.get(k).getAddress());
                                    am.setItem_type("sc");
                                    sm.getAbnormalList().add(am);
                                }
                            }
                        }
                        for(int k=0;k<eimList.size();k++)
                        {
                            if(sim.getItem_key().equals(eimList.get(k).getItem_key()))
                            {
                                if(eimList.get(k).getStatus()!=1)
                                {
                                    sm.setStatus(2);
                                    sm.setScore(sm.getScore()-sim.getScore());
                                    sm.setError_count(sm.getError_count()+1);
                                    String message="";
                                    if(eimList.get(k).getStatus()==3)//告警
                                    {
                                        message="当前在告警状态";
                                    }
                                    else if(eimList.get(k).getStatus()==4)//故障
                                    {
                                        message="当前在故障状态";
                                    }
                                    else if(eimList.get(k).getStatus()==5)//限制
                                    {
                                        message="当前在限制状态";
                                    }
                                    else if(eimList.get(k).getStatus()==6)//冻结
                                    {
                                        message="当前在冻结状态";
                                    }
                                    else if(eimList.get(k).getStatus()==0)//离线
                                    {
                                        message="当前在离线状态";
                                    }
                                    AbnormalModel am=new AbnormalModel();
                                    am.setItem_key(eimList.get(k).getItem_key());
                                    am.setItem_name(eimList.get(k).getItem_name());
                                    am.setMessage(eimList.get(k).getItem_name()+message);
                                    am.setStatus(eimList.get(k).getStatus());
                                    am.setItemgroup_sn(eimList.get(k).getItemgroup_sn());
                                    //SW尚未？
                                    am.setItem_type("sw");
                                    sm.getAbnormalList().add(am);
                                }
                            }
                        }
                    }
                }
                if(sm.getScore()<0)
                {
                    sm.setScore(0);
                }
                if(sm.getError_count()>0)
                {
                    sm.setMessage("共检测了"+sti_list.size()+"项，发现"+sm.getError_count()+"个问题");
                }
                else
                {
                    sm.setMessage("共检测了"+sti_list.size()+"项，检测正常");
                }
                jcCount=sti_list.size()+jcCount;
                list.set(i,sm);
            }
        }
        if(list!=null)
        {
            result.setResultErrorMsg("获取数据完毕,总共"+list.size()+"条数据");
        }
        else
        {
            result.setResultErrorMsg("获取数据完毕,list为null");
        }

        SignalRunSituationResultModel sm=new SignalRunSituationResultModel();
        sm.setList(list);
        int errorCount=0;
        for(int i=0;i<list.size();i++)
        {
            errorCount=list.get(i).getError_count()+errorCount;
        }
        String resultMessage="共检测了"+jcCount+"项，发现"+errorCount+"个问题";
        sm.setResultMessage(resultMessage);
        result.setResult(sm);
        return result;
    }


    @Value("${setMainHost}")
    private String setMainHost;

    @ApiOperation(value = "根据itemKey获取传感器实时数据")
    @RequestMapping(value = "/query/RealDataByItemKey",method = RequestMethod.POST,produces = "application/json;charset=UTF-8")
    @ApiImplicitParams({
            @ApiImplicitParam(name="obj",value = "{\"itemKey\": \"0081\"}",paramType ="body",required = false)
    })
    @ResponseBody
    public ResultJson queryRealDataByItemKey(@RequestBody JSONObject obj, HttpServletRequest request)
    {
        ResultJson result=new ResultJson();
        ScRealItemDataModel srdm=new ScRealItemDataModel();
        String itemKey="";
        try {
            itemKey = (String) obj.get("itemKey");
        } catch (Exception e) {
            result.setResultErrorMsg("参数itemKey需要设置");
            result.setResultFlag(-1);
            return result;
        }
        if((itemKey!=null)&&(!itemKey.equals("")))
        {
            List<AttributeToFieldModel> AttributeToFieldList = sc_data_service.queryAttributeToFieldList();
            if(itemKey.equals("0011"))
            {
                String data = RequestUnit.doPost("http://"+setMainHost+"/iot_hf/C2000Value/query/getListByTime","{\"limit\": 1}");
                JSONObject json = JSONObject.parseObject(data);
                result.setResultFlag(Integer.parseInt(json.get("resultFlag").toString()));
                result.setResultErrorMsg(json.get("resultErrorMsg").toString());
                JSONArray resultArray = json.getJSONArray("result");

                Map<String,Object> map = new HashMap();
                if(resultArray.size()<0){
                    result.setResultErrorMsg("暂无数据");
                    result.setResultFlag(-1);
                    return result;
                }else {
                    JSONObject resultValue = resultArray.getJSONObject(0);

                    map.put("itemKey","0011");
                    map.put("itemName","转台电机重点部位温度采集器");
                    map.put("status","0");
                    map.put("collectionTime",resultValue.get("ts"));
                    map.put("status","0");
                    map.put("itemAlarmLevel","0");
                    map.put("itemAlarmMessage","转台电机温度数据正常");
                    map.put("itemAlarmTime",resultValue.get("ts"));

                    ScWarningStrategy scWarningStrategy = new ScWarningStrategy();
                    scWarningStrategy.setCollector("0011");
                    List<Object> list = new ArrayList<>();

                    for(int i=1;i<8;i++){
                        Map<String,Object> mapResult = new HashMap();
                        String channel = "ch"+i;
                        Object ch = resultValue.get(channel);
                        mapResult.put("fieldNum",i-1);
                        mapResult.put("fieldName","Machinery_Temperature"+i);
                        mapResult.put("fieldValue",ch);

                        //根据类型获取阈值范围
                        scWarningStrategy.setDataitem(channel);
                        List<ScWarningStrategy> ScWarningList = scWarningStrategyService.queryAll(scWarningStrategy);
                        Map checkStart = checkDataUnit.checkData(new BigDecimal(ch.toString()),ScWarningList);
                        mapResult.put("fieldUnit","摄氏度");
                        mapResult.put("fieldType","1");
                        mapResult.put("alarmStatus",checkStart.get("checkDataStart"));
                        mapResult.put("alarmLevel","0");
                        mapResult.put("alarmMessage",checkStart.get("alarmMessage"));
                        mapResult.put("alarmTime",resultValue.get("ts"));
                        mapResult.put("quantityKey","0011_"+channel);
                        list.add(mapResult);
                    }

                    Map<String,Object> mapResult = new HashMap();
                    mapResult = new HashMap();
                    mapResult.put("fieldNum","8");
                    mapResult.put("fieldName","Machinery_On_Off");
                    mapResult.put("fieldValue","0");
                    mapResult.put("fieldUnit","电机开机");
                    mapResult.put("fieldType","1");
                    mapResult.put("alarmStatus","0");
                    mapResult.put("alarmLevel","0");
                    mapResult.put("alarmMessage","正常");
                    mapResult.put("alarmTime",resultValue.get("ts"));
                    mapResult.put("quantityKey","0011_"+88);
                    list.add(mapResult);

                    map.put("fieldDataList",list);
                    result.setResult(map);
                }

            }
            else if(itemKey.equals("0021"))
            {
                String data = RequestUnit.doPost("http://"+setMainHost+"/iot_hf/Adc/query/getListByTime","{\"limit\": 2000}");
                JSONObject json = JSONObject.parseObject(data);
                BigDecimal cs = new BigDecimal(2000);
                JSONArray resultTimeArray = json.getJSONArray("result");

                if(resultTimeArray.size()<0){
                    result.setResultErrorMsg("暂无数据");
                    result.setResultFlag(-1);
                    return result;
                }else {

                    JSONObject resultTimeValue = resultTimeArray.getJSONObject(0);
                    Object resultTime = new Object();
                    resultTime = resultTimeValue.get("ts");

                    result.setResultFlag(Integer.parseInt(json.get("resultFlag").toString()));
                    result.setResultErrorMsg(json.get("resultErrorMsg").toString());
                    Map<String, Object> map = new HashMap();
                    map.put("itemKey", "0021");
                    map.put("status", "0");
                    map.put("itemName", "转台电机重点部位振动加速度采集器");
                    map.put("collectionTime", resultTime);
                    map.put("status", "0");
                    map.put("itemAlarmLevel", "0");
                    map.put("itemAlarmMessage", "雷达台站转机振动数值近3天增加了40%,已经接近轻微异常阈值,建议技保人员前去排查");
                    map.put("itemAlarmTime", resultTime);

                    ScWarningStrategy scWarningStrategy = new ScWarningStrategy();
                    scWarningStrategy.setCollector("0021");

                    List<Object> list = new ArrayList<>();
                    Map<String, Object> mapResult = new HashMap();
                    mapResult.put("fieldNum", "0");
                    mapResult.put("fieldName", "Machinery_Vibration1");
                    mapResult.put("fieldValue", "9.98");
                    mapResult.put("fieldUnit", "mm/s");
                    mapResult.put("pointList", "[]");
                    mapResult.put("fieldType", "1");
                    mapResult.put("alarmStatus", "2");
                    mapResult.put("alarmLevel", "0");
                    mapResult.put("alarmMessage", "雷达台站转机振动数值近3天增加了40%,已经接近轻微异常阈值,建议技保人员前去排查");
                    mapResult.put("alarmTime", resultTime);
                    mapResult.put("quantityKey", "0021_" + 00);
                    list.add(mapResult);

                    for (int j = 1; j < 4; j++) {
                        mapResult = new HashMap();
                        String channel = "ch" + j;
                        mapResult.put("fieldNum", j);
                        mapResult.put("fieldName", "Machinery_Vibration" + (j + 1));

                        BigDecimal sum = BigDecimal.valueOf(0);
                        List<Object> arrList = new ArrayList<>();
                        JSONArray resultArray = json.getJSONArray("result");
                        Object time = new Object();
                        for (int i = 0; i < resultArray.size(); i++) {
                            JSONObject resultValue = resultArray.getJSONObject(i);
                            BigDecimal num = new BigDecimal(resultValue.get(channel).toString());
                            sum = sum.add(num);
                            arrList.add(num);
                            time = resultValue.get("ts");
                        }

                        mapResult.put("fieldValue", sum.divide(cs));
                        //根据类型获取阈值范围
                        scWarningStrategy.setDataitem(channel);
                        List<ScWarningStrategy> ScWarningList = scWarningStrategyService.queryAll(scWarningStrategy);
                        Map checkStart = checkDataUnit.checkData(new BigDecimal(sum.divide(cs).toString()), ScWarningList);

                        mapResult.put("fieldUnit", "mm/s");
                        mapResult.put("pointList", arrList.toArray());
                        mapResult.put("fieldType", "1");
                        mapResult.put("alarmStatus", checkStart.get("checkDataStart"));
                        mapResult.put("alarmLevel", "0");
                        mapResult.put("alarmMessage", checkStart.get("alarmMessage"));
                        mapResult.put("alarmTime", time);
                        mapResult.put("quantityKey", "0021_" + channel);
                        list.add(mapResult);
                    }


                    mapResult = new HashMap();
                    mapResult.put("fieldNum", "4");
                    mapResult.put("fieldName", "Machinery_On_Off");
                    mapResult.put("fieldValue", "0");
                    mapResult.put("fieldUnit", "电机开机");
                    mapResult.put("fieldType", "1");
                    mapResult.put("alarmStatus", "0");
                    mapResult.put("alarmLevel", "0");
                    mapResult.put("alarmMessage", "雷达台站转机振动数值近3天增加了40%,已经接近轻微异常阈值,建议技保人员前去排查");
                    mapResult.put("alarmTime", resultTime);
                    mapResult.put("quantityKey", "0021_" + 44);
                    list.add(mapResult);

                    map.put("fieldDataList", list);
                    result.setResult(map);
                }

            }
            else if(itemKey.equals("0051"))
            {
                String data = RequestUnit.doPost("http://"+setMainHost+"/iot_hf/AngleValue/query/getListByTime","{\"limit\": 1}");
                JSONObject json = JSONObject.parseObject(data);
                JSONArray resultArray = json.getJSONArray("result");

                result.setResultFlag(Integer.parseInt(json.get("resultFlag").toString()));
                result.setResultErrorMsg(json.get("resultErrorMsg").toString());
                Map<String,Object> map = new HashMap();

                if(resultArray.size()<0){
                    result.setResultErrorMsg("暂无数据");
                    result.setResultFlag(-1);
                    return result;
                }else {
                    JSONObject resultTimeValue = resultArray.getJSONObject(0);
                    Object resultTime = new Object();
                    resultTime = resultTimeValue.get("ts");

                    map.put("itemKey","0051");
                    map.put("status","0");
                    map.put("itemName","雷达天线倾角采集器");
                    map.put("collectionTime",resultTime);
                    map.put("status","0");                    map.put("itemAlarmLevel","0");
                    map.put("itemAlarmMessage","雷达天线倾角正常");
                    map.put("itemAlarmTime",resultTime);

                    ScWarningStrategy scWarningStrategy = new ScWarningStrategy();
                    scWarningStrategy.setCollector("0051");

                    List<Object> list = new ArrayList<>();

                    for(int i=1;i<4;i++){
                        Map<String,Object> mapResult = new HashMap();
                        JSONObject resultValue = resultArray.getJSONObject(0);
                        String channel = "ch"+i;
                        Object ch = resultValue.get(channel);
                        mapResult.put("fieldNum","0");
                        if("1".equals(channel)){
                            mapResult.put("fieldName","Antenna_Antenna_X");
                        }else if("2".equals(channel)){
                            mapResult.put("fieldName","Antenna_Antenna_Y");
                        }else{
                            mapResult.put("fieldName","Antenna_Antenna_Z");
                        }

                        //根据类型获取阈值范围
                        scWarningStrategy.setDataitem(channel);
                        List<ScWarningStrategy> ScWarningList = scWarningStrategyService.queryAll(scWarningStrategy);
                        Map checkStart = checkDataUnit.checkData(new BigDecimal(ch.toString()),ScWarningList);

                        mapResult.put("fieldValue",ch);
                        mapResult.put("fieldUnit","度");
                        mapResult.put("fieldType","1");
                        mapResult.put("alarmStatus",checkStart.get("checkDataStart"));
                        mapResult.put("alarmLevel","0");
                        mapResult.put("alarmMessage",checkStart.get("alarmMessage"));
                        mapResult.put("alarmTime",resultValue.get("ts"));
                        mapResult.put("quantityKey","0051_"+channel);
                        list.add(mapResult);
                    }


                    Map<String,Object> mapResult = new HashMap();
                    mapResult = new HashMap();
                    mapResult.put("fieldNum","3");
                    mapResult.put("fieldName","Battery_Level");
                    mapResult.put("fieldValue","49.98");
                    mapResult.put("fieldUnit","百分比");
                    mapResult.put("fieldType","1");
                    mapResult.put("alarmStatus","0");
                    mapResult.put("alarmLevel","0");
                    mapResult.put("alarmMessage","正常");
                    mapResult.put("alarmTime",resultTime);
                    mapResult.put("quantityKey","0051_"+33);
                    list.add(mapResult);

                    map.put("fieldDataList",list);

                    result.setResult(map);
                }

            }
            else if(itemKey.equals("0081"))
            {
                List<DvorStatusModel> dvorStatusModelList=sc_data_service.queryDvorStatusRealData();
                List<ScItemModel> scItemList=sc_data_service.queryScItemListbyKey(itemKey);
                if((dvorStatusModelList!=null)&&(dvorStatusModelList.size()>0))
                {
                    DvorStatusModel dsm=dvorStatusModelList.get(0);
                    Class cls = dsm.getClass();
                    Field[] fields = cls.getDeclaredFields();
                    int haveAlarm=0;
                    for(int i=0; i<fields.length; i++){
                        Field f = fields[i];
                        f.setAccessible(true);
                        try {
                            FieldDataModel fdm=new FieldDataModel();
                            fdm.setFieldNum(i);
                            fdm.setFieldName(f.getName());
                            fdm.setFieldValue(f.get(dsm).toString());
                            if(f.get(dsm).toString().equals("Green")) {
                                fdm.setAlarmStatus(0);//0正常，1告警，2关机
                                fdm.setAlarmMessage("正常");
                                fdm.setAlarmLevel(0);//0表示无告警，1轻微，2一般，3严重
                            }
                            else if(f.get(dsm).toString().equals("Yellow")) {
                                fdm.setAlarmStatus(1);//0正常，1告警，2关机
                                fdm.setAlarmMessage("一般故障告警");
                                fdm.setAlarmLevel(2);//0表示无告警，1轻微，2一般，3严重
                                haveAlarm=1;
                            }
                            else if(f.get(dsm).toString().equals("Black")) {
                                fdm.setAlarmStatus(2);//0正常，1告警，2关机
                                fdm.setAlarmMessage("本模块关机");
                                fdm.setAlarmLevel(0);//0表示无告警，1轻微，2一般，3严重
                            }
                            else if(f.get(dsm).toString().equals("Red")) {
                                fdm.setAlarmStatus(1);//0正常，1告警，2关机
                                fdm.setAlarmMessage("严重故障告警");
                                fdm.setAlarmLevel(3);//0表示无告警，1轻微，2一般，3严重
                                haveAlarm=1;
                            }
                            fdm.setAlarmTime(dsm.getDTime().getTime());
                            fdm.setFieldType(0);//0表示状态型，1表示数值型
                            fdm.setFieldUnit("Red/Green/Black/Yellow");
                            fdm.setQuantityKey("0081_"+f.getName());
                            srdm.getFieldDataList().add(fdm);

                            if("ImageName".equals(f.getName())){
                                String photoStr = fdm.getFieldValue().replaceAll("D:/OcrImages","http://192.168.100.108:9000");
                                fdm.setFieldValue(photoStr);
                            }
                        } catch (IllegalAccessException e) {
                            e.printStackTrace();
                            result.setResultFlag(-1);
                            result.setResultErrorMsg(e.getMessage());
                            return result;
                        }
                    }
                    if(scItemList!=null&&scItemList.size()>0)
                    {
                        srdm.setItemName(scItemList.get(0).getItem_name());
                    }
                    srdm.setCollectionTime(dsm.getDTime().getTime());
                    srdm.setItemKey(itemKey);
                    if(haveAlarm==1)
                    {
                        srdm.setStatus(1);//0正常，1告警，2离线
                        srdm.setItemAlarmLevel(2);
                        srdm.setItemAlarmTime(dsm.getDTime().getTime());
                        srdm.setItemAlarmMessage("dvor设备运行状态有一般告警");
                    }
                    else
                    {
                        srdm.setStatus(0);//0正常，1告警，2离线
                        srdm.setItemAlarmLevel(0);
                        srdm.setItemAlarmTime(dsm.getDTime().getTime());
                        srdm.setItemAlarmMessage("dvor设备运行状态运行正常");
                    }
                    result.setResultFlag(0);
                    result.setResult(srdm);
                    result.setResultErrorMsg("查询成功");
                }
                else
                {
                    result.setResultFlag(-1);
                    result.setResultErrorMsg("查询结果为空");
                }
            }
            else if(itemKey.equals("0082"))
            {
                List<DvorDataModel> dvorDataModelList=sc_data_service.queryDvorDataRealData();
                List<ScItemModel> scItemList=sc_data_service.queryScItemListbyKey(itemKey);
                if((dvorDataModelList!=null)&&(dvorDataModelList.size()>0))
                {
                    DvorDataModel ddm=dvorDataModelList.get(0);
                    Class cls = ddm.getClass();
                    Field[] fields = cls.getDeclaredFields();
                    int haveAlarm=0;
                    for(int i=0; i<fields.length; i++){
                        Field f = fields[i];
                        f.setAccessible(true);
                        try {
                            FieldDataModel fdm=new FieldDataModel();
                            fdm.setFieldNum(i);
                            fdm.setFieldName(f.getName());
                            fdm.setQuantityKey("0082_"+f.getName());
                            fdm.setFieldValue(f.get(ddm).toString());
                            fdm.setAlarmStatus(0);//0正常，1告警，2关机
                            fdm.setAlarmMessage("正常");
                            fdm.setAlarmLevel(0);//0表示无告警，1轻微，2一般，3严重
                            fdm.setAlarmTime(ddm.getDTime().getTime());
                            fdm.setFieldType(1);//0表示状态型，1表示数值型
                            fdm.setFieldUnit("float");
                            srdm.getFieldDataList().add(fdm);

                            if("ImageName".equals(f.getName())){
                                String photoStr = fdm.getFieldValue().replaceAll("D:/OcrImages","http://192.168.100.108:9000");
                                fdm.setFieldValue(photoStr);
                            }
                        } catch (IllegalAccessException e) {
                            e.printStackTrace();
                            result.setResultFlag(-1);
                            result.setResultErrorMsg(e.getMessage());
                            return result;
                        }
                    }
                    if(scItemList!=null&&scItemList.size()>0)
                    {
                        srdm.setItemName(scItemList.get(0).getItem_name());
                    }
                    srdm.setCollectionTime(ddm.getDTime().getTime());
                    srdm.setItemKey(itemKey);
                    if(haveAlarm==1)
                    {
                        srdm.setStatus(1);//0正常，1告警，2离线
                        srdm.setItemAlarmLevel(2);
                        srdm.setItemAlarmTime(ddm.getDTime().getTime());
                        srdm.setItemAlarmMessage("dvor设备运行数据有一般告警");
                    }
                    else
                    {
                        srdm.setStatus(0);//0正常，1告警，2离线
                        srdm.setItemAlarmLevel(0);
                        srdm.setItemAlarmTime(ddm.getDTime().getTime());
                        srdm.setItemAlarmMessage("dvor设备数据正常");
                    }
                    result.setResultFlag(0);
                    result.setResult(srdm);
                    result.setResultErrorMsg("查询成功");
                }
                else
                {
                    result.setResultFlag(-1);
                    result.setResultErrorMsg("查询结果为空");
                }
            }
            else if(itemKey.equals("0083"))
            {
                List<DmeDataModel> dmeDataModelList=sc_data_service.queryDmeDataRealData();
                List<ScItemModel> scItemList=sc_data_service.queryScItemListbyKey(itemKey);
                if((dmeDataModelList!=null)&&(dmeDataModelList.size()>0))
                {
                    DmeDataModel ddm=dmeDataModelList.get(0);
                    Class cls = ddm.getClass();
                    Field[] fields = cls.getDeclaredFields();
                    int haveAlarm=0;
                    for(int i=0; i<fields.length; i++){
                        Field f = fields[i];
                        f.setAccessible(true);
                        try {
                            FieldDataModel fdm=new FieldDataModel();
                            fdm.setFieldNum(i);
                            fdm.setFieldName(f.getName());
                            fdm.setQuantityKey("0083_"+f.getName());
                            fdm.setFieldValue(f.get(ddm).toString());
                            fdm.setAlarmTime(ddm.getDTime().getTime());
                            fdm.setFieldType(1);//0表示状态型，1表示数值型
                            fdm.setFieldUnit("float");
                            fdm=getFieldAlarmByStrategyConfig(itemKey,fdm,AttributeToFieldList);
                            srdm.getFieldDataList().add(fdm);

                            if("ImageName".equals(f.getName())){
                                String photoStr = fdm.getFieldValue().replaceAll("D:/OcrImages","http://192.168.100.108:9000");
                                fdm.setFieldValue(photoStr);
                            }
                        } catch (IllegalAccessException e) {
                            e.printStackTrace();
                            result.setResultFlag(-1);
                            result.setResultErrorMsg(e.getMessage());
                            return result;
                        }
                    }
                    if(scItemList!=null&&scItemList.size()>0)
                    {
                        srdm.setItemName(scItemList.get(0).getItem_name());
                    }
                    srdm.setCollectionTime(ddm.getDTime().getTime());
                    srdm.setItemKey(itemKey);
                    if(haveAlarm==1)
                    {
                        srdm.setStatus(1);//0正常，1告警，2离线
                        srdm.setItemAlarmLevel(2);
                        srdm.setItemAlarmTime(ddm.getDTime().getTime());
                        srdm.setItemAlarmMessage("dme设备运行数据有一般告警");
                    }
                    else
                    {
                        srdm.setStatus(0);//0正常，1告警，2离线
                        srdm.setItemAlarmLevel(0);
                        srdm.setItemAlarmTime(ddm.getDTime().getTime());
                        srdm.setItemAlarmMessage("dme设备数据正常");
                    }
                    result.setResultFlag(0);
                    result.setResult(srdm);
                    result.setResultErrorMsg("查询成功");
                }
                else
                {
                    result.setResultFlag(-1);
                    result.setResultErrorMsg("查询结果为空");
                }
            }
            else if(itemKey.equals("0084"))
            {
                List<ThalesStatusModel> thalesStatusModelList=sc_data_service.queryThalesStatusRealData();
                List<ScItemModel> scItemList=sc_data_service.queryScItemListbyKey(itemKey);
                if((thalesStatusModelList!=null)&&(thalesStatusModelList.size()>0))
                {
                    ThalesStatusModel tsm=thalesStatusModelList.get(0);
                    Class cls = tsm.getClass();
                    Field[] fields = cls.getDeclaredFields();
                    int haveAlarm=0;
                    for(int i=0; i<fields.length; i++){
                        Field f = fields[i];
                        f.setAccessible(true);
                        try {
                            FieldDataModel fdm=new FieldDataModel();
                            fdm.setFieldNum(i);
                            fdm.setFieldName(f.getName());
                            fdm.setQuantityKey("0084_"+f.getName());
                            fdm.setFieldValue(f.get(tsm).toString());
                            if(f.get(tsm).toString().equals("Green")) {
                                fdm.setAlarmStatus(0);//0正常，1告警，2关机
                                fdm.setAlarmMessage("正常");
                                fdm.setAlarmLevel(0);//0表示无告警，1轻微，2一般，3严重
                            }
                            else if(f.get(tsm).toString().equals("Yellow")) {
                                fdm.setAlarmStatus(1);//0正常，1告警，2关机
                                fdm.setAlarmMessage("一般故障告警");
                                fdm.setAlarmLevel(2);//0表示无告警，1轻微，2一般，3严重
                                haveAlarm=1;
                            }
                            else if(f.get(tsm).toString().equals("Black")) {
                                fdm.setAlarmStatus(2);//0正常，1告警，2关机
                                fdm.setAlarmMessage("本模块关机");
                                fdm.setAlarmLevel(0);//0表示无告警，1轻微，2一般，3严重
                            }
                            else if(f.get(tsm).toString().equals("Red")) {
                                fdm.setAlarmStatus(1);//0正常，1告警，2关机
                                fdm.setAlarmMessage("严重故障告警");
                                fdm.setAlarmLevel(3);//0表示无告警，1轻微，2一般，3严重
                                haveAlarm=1;
                            }
                            fdm.setAlarmTime(tsm.getDTime().getTime());
                            fdm.setFieldType(0);//0表示状态型，1表示数值型
                            fdm.setFieldUnit("Red/Green/Black/Yellow");
                            srdm.getFieldDataList().add(fdm);
                            if("ImageName".equals(f.getName())){
                                String photoStr = tsm.getImageName().replaceAll("D:/OcrImages","http://192.168.100.102:9000");
                                fdm.setFieldValue(photoStr);
                            }
                        } catch (IllegalAccessException e) {
                            e.printStackTrace();
                            result.setResultFlag(-1);
                            result.setResultErrorMsg(e.getMessage());
                            return result;
                        }
                    }
                    if(scItemList!=null&&scItemList.size()>0)
                    {
                        srdm.setItemName(scItemList.get(0).getItem_name());
                    }
                    srdm.setCollectionTime(tsm.getDTime().getTime());
                    srdm.setItemKey(itemKey);
                    if(haveAlarm==1)
                    {
                        srdm.setStatus(1);//0正常，1告警，2离线
                        srdm.setItemAlarmLevel(2);
                        srdm.setItemAlarmTime(tsm.getDTime().getTime());
                        srdm.setItemAlarmMessage("Thales运行状态有一般告警");
                    }
                    else
                    {
                        srdm.setStatus(0);//0正常，1告警，2离线
                        srdm.setItemAlarmLevel(0);
                        srdm.setItemAlarmTime(tsm.getDTime().getTime());
                        srdm.setItemAlarmMessage("Thales运行状态运行正常");
                    }
                    result.setResultFlag(0);
                    result.setResult(srdm);
                    result.setResultErrorMsg("查询成功");
                }
                else
                {
                    result.setResultFlag(-1);
                    result.setResultErrorMsg("查询结果为空");
                }
            }
            else if(itemKey.equals("0085"))
            {
                Ocrtable3 tsm = ocrtable3Service.getDataByLimit();
                List<ScItemModel> scItemList=sc_data_service.queryScItemListbyKey(itemKey);
                if(tsm!=null)
                {
                    Class cls = tsm.getClass();
                    Field[] fields = cls.getDeclaredFields();
                    int haveAlarm=0;
                    for(int i=0; i<fields.length; i++){
                        Field f = fields[i];
                        f.setAccessible(true);
                        try {
                            FieldDataModel fdm=new FieldDataModel();
                            fdm.setFieldNum(i);
                            fdm.setFieldName(f.getName());
                            fdm.setQuantityKey("0085_"+f.getName());
                            fdm.setFieldValue(f.get(tsm).toString());

                            if("height".equals(f.getName())){
                                //根据类型获取阈值范围
                                ScWarningStrategy scWarningStrategy = new ScWarningStrategy();
                                scWarningStrategy.setCollector("0085");
                                scWarningStrategy.setDataitem(f.getName());
                                List<ScWarningStrategy> ScWarningList = scWarningStrategyService.queryAll(scWarningStrategy);
                                Map checkStart = checkDataUnit.checkData(new BigDecimal(f.get(tsm).toString()),ScWarningList);

                                fdm.setAlarmMessage(checkStart.get("alarmMessage").toString());
                                fdm.setAlarmStatus(Integer.parseInt(checkStart.get("checkDataStart").toString()));//0表示无告警，1轻微，2一般，3严重
                                if(Integer.parseInt(checkStart.get("checkDataStart").toString()) == DataDictionary.CHECK_DATA_STATUS.NORMAL){
                                    fdm.setAlarmLevel(DataDictionary.CHECK_DATA_STATUS.NORMAL);

                                }else {
                                    fdm.setAlarmLevel(DataDictionary.CHECK_DATA_STATUS.MINOR);
                                    haveAlarm=1;
                                }
                            }else if("imagename".equals(f.getName())){
                                String photoStr = tsm.getImagename().replaceAll("D:/OcrImages","http://192.168.100.102:9000");
                                fdm.setFieldValue(photoStr);
                            }else{
                                fdm.setAlarmMessage(null);
                                fdm.setAlarmStatus(null);
                                fdm.setAlarmLevel(null);
                            }

                            fdm.setAlarmTime(tsm.getDtime().getTime());
                            fdm.setFieldType(1);//0表示状态型，1表示数值型
                            fdm.setFieldUnit("0/1/2/3/4");
                            srdm.getFieldDataList().add(fdm);
                        } catch (IllegalAccessException e) {
                            e.printStackTrace();
                            result.setResultFlag(-1);
                            result.setResultErrorMsg(e.getMessage());
                            return result;
                        }
                    }

                    if(scItemList!=null&&scItemList.size()>0)
                    {
                        srdm.setItemName(scItemList.get(0).getItem_name());
                    }
                    srdm.setCollectionTime(tsm.getDtime().getTime());
                    srdm.setItemKey(itemKey);
                    if(haveAlarm==1)
                    {
                        srdm.setStatus(1);//0正常，1告警，2离线
                        srdm.setItemAlarmLevel(2);
                        srdm.setItemAlarmTime(tsm.getDtime().getTime());
                        srdm.setItemAlarmMessage("状态有告警");
                    }
                    else
                    {
                        srdm.setStatus(0);//0正常，1告警，2离线
                        srdm.setItemAlarmLevel(0);
                        srdm.setItemAlarmTime(tsm.getDtime().getTime());
                        srdm.setItemAlarmMessage("Thales运行状态运行正常");
                    }
                    result.setResultFlag(0);
                    result.setResult(srdm);
                    result.setResultErrorMsg("查询成功");
                }
                else
                {
                    result.setResultFlag(-1);
                    result.setResultErrorMsg("查询结果为空");
                }
            }
            else if(itemKey.equals("0086"))
            {
                Ocrtable4 tsm = ocrtable4Service.getDataByLimit();
                List<ScItemModel> scItemList=sc_data_service.queryScItemListbyKey(itemKey);
                if(tsm != null){
                    Date time = new Date(tsm.getDtime().getTime() - 3600000);
                    Ocrtable4 oldTsm = ocrtable4Service.getDataByTimeLimit(time);
                    if(oldTsm!=null)
                    {
                        Class cls = tsm.getClass();
                        Field[] fields = cls.getDeclaredFields();
                        Integer countAlarm=0;
                        Integer areaAlarm=0;
                        FieldDataModel fdm=new FieldDataModel();
                        if(tsm.getCount()-oldTsm.getCount()>0){
                            countAlarm=1;
                        }
                        Float num = tsm.getArea()-oldTsm.getArea();
                        if(num>2000){
                            areaAlarm=1;
                        }


                        //油渍差数
                        fdm.setFieldNum(0);
                        fdm.setFieldName("count");
                        fdm.setQuantityKey("0086_count");
                        fdm.setFieldValue((tsm.getCount()-oldTsm.getCount())+"");
                        fdm.setFieldUnit("油渍差数");
                        fdm.setFieldType(1);
                        fdm.setAlarmTime(tsm.getDtime().getTime());
                        //根据类型获取阈值范围
                        ScWarningStrategy scWarningStrategy = new ScWarningStrategy();
                        scWarningStrategy.setCollector("0086");
                        scWarningStrategy.setDataitem("count");
                        List<ScWarningStrategy> ScWarningList = scWarningStrategyService.queryAll(scWarningStrategy);
                        Map checkStart = checkDataUnit.checkData(new BigDecimal(tsm.getCount()-oldTsm.getCount()),ScWarningList);
                        fdm.setAlarmMessage(checkStart.get("alarmMessage").toString());
                        fdm.setAlarmStatus(Integer.parseInt(checkStart.get("checkDataStart").toString()));//0表示无告警，1轻微，2一般，3严重
                        fdm.setAlarmLevel(null);
                        srdm.getFieldDataList().add(fdm);

                        //油渍面积像素差
                        fdm = new FieldDataModel();
                        fdm.setFieldNum(1);
                        fdm.setFieldName("area");
                        fdm.setQuantityKey("0086_area");
                        fdm.setFieldValue((tsm.getArea()-oldTsm.getArea())+"");
                        fdm.setFieldUnit("油渍面积像素差");
                        fdm.setFieldType(1);
                        fdm.setAlarmTime(tsm.getDtime().getTime());
                        //根据类型获取阈值范围
                        scWarningStrategy.setDataitem("area");
                        ScWarningList = scWarningStrategyService.queryAll(scWarningStrategy);
                        checkStart = checkDataUnit.checkData(new BigDecimal(tsm.getArea()-oldTsm.getArea()),ScWarningList);
                        fdm.setAlarmMessage(checkStart.get("alarmMessage").toString());
                        fdm.setAlarmStatus(Integer.parseInt(checkStart.get("checkDataStart").toString()));//0表示无告警，1轻微，2一般，3严重
                        fdm.setAlarmLevel(null);
                        srdm.getFieldDataList().add(fdm);

                        //漏油速度ML每秒
                        fdm = new FieldDataModel();
                        fdm.setFieldNum(2);
                        fdm.setFieldName("speed");
                        fdm.setQuantityKey("0086_speed");
                        fdm.setFieldValue(((tsm.getArea()-tsm.getArea())/3600000)+"");
                        fdm.setFieldUnit("漏油速度ML每秒");
                        fdm.setFieldType(1);
                        fdm.setAlarmTime(tsm.getDtime().getTime());
                        //根据类型获取阈值范围
                        scWarningStrategy.setDataitem("area");
                        ScWarningList = scWarningStrategyService.queryAll(scWarningStrategy);
                        checkStart = checkDataUnit.checkData(new BigDecimal(tsm.getArea()-oldTsm.getArea()),ScWarningList);
                        fdm.setAlarmMessage(checkStart.get("alarmMessage").toString());
                        fdm.setAlarmStatus(Integer.parseInt(checkStart.get("checkDataStart").toString()));//0表示无告警，1轻微，2一般，3严重
                        fdm.setAlarmLevel(null);
                        srdm.getFieldDataList().add(fdm);

                        //是否漏油
                        fdm = new FieldDataModel();
                        fdm.setFieldNum(3);
                        fdm.setFieldName("oilleak");
                        fdm.setQuantityKey("0086_oilleak");
                        fdm.setFieldValue(areaAlarm.toString());
                        fdm.setFieldUnit("是否漏油");
                        fdm.setFieldType(1);
                        fdm.setAlarmTime(tsm.getDtime().getTime());
                        //根据类型获取阈值范围
                        scWarningStrategy.setDataitem("count");
                        ScWarningList = scWarningStrategyService.queryAll(scWarningStrategy);
                        checkStart = checkDataUnit.checkData(new BigDecimal(tsm.getCount()-oldTsm.getCount()),ScWarningList);
                        fdm.setAlarmMessage(checkStart.get("alarmMessage").toString());
                        fdm.setAlarmStatus(Integer.parseInt(checkStart.get("checkDataStart").toString()));//0表示无告警，1轻微，2一般，3严重
                        fdm.setAlarmLevel(null);
                        srdm.getFieldDataList().add(fdm);

                        //采集时间
                        fdm = new FieldDataModel();
                        fdm.setFieldNum(4);
                        fdm.setFieldName("dtime");
                        fdm.setQuantityKey("0086_dtime");
                        fdm.setFieldValue(tsm.getDtime().toString());
                        fdm.setFieldUnit("采集时间");
                        fdm.setFieldType(1);
                        fdm.setAlarmTime(tsm.getDtime().getTime());
                        fdm.setAlarmMessage(null);
                        fdm.setAlarmStatus(null);
                        fdm.setAlarmLevel(null);
                        srdm.getFieldDataList().add(fdm);

                        //采集图片
                        fdm = new FieldDataModel();
                        fdm.setFieldNum(5);
                        fdm.setFieldName("imagename");
                        fdm.setQuantityKey("0086_imagename");
                        String photoStr = tsm.getImagename().replaceAll("D:/OcrImages","http://192.168.100.102:9000");
                        fdm.setFieldValue(photoStr);
                        fdm.setFieldUnit("采集图片");
                        fdm.setFieldType(1);
                        fdm.setAlarmTime(tsm.getDtime().getTime());
                        fdm.setAlarmMessage(null);
                        fdm.setAlarmStatus(null);
                        fdm.setAlarmLevel(null);
                        srdm.getFieldDataList().add(fdm);

                        //油渍当前个数
                        fdm = new FieldDataModel();
                        fdm.setFieldNum(6);
                        fdm.setFieldValue(tsm.getCount().toString());
                        fdm.setFieldUnit("油渍当前个数");
                        fdm.setFieldType(1);
                        fdm.setAlarmTime(tsm.getDtime().getTime());
                        srdm.getFieldDataList().add(fdm);

                        //油渍当前像素面积
                        fdm = new FieldDataModel();
                        fdm.setFieldNum(7);
                        fdm.setFieldValue(tsm.getArea().toString());
                        fdm.setFieldUnit("油渍当前像素面积");
                        fdm.setFieldType(1);
                        fdm.setAlarmTime(tsm.getDtime().getTime());
                        srdm.getFieldDataList().add(fdm);

                        if(scItemList!=null&&scItemList.size()>0)
                        {
                            srdm.setItemName(scItemList.get(0).getItem_name());
                        }
                        srdm.setCollectionTime(tsm.getDtime().getTime());
                        srdm.setItemKey(itemKey);
                        if(areaAlarm == 1)
                        {
                            srdm.setStatus(1);//0正常，1告警，2离线
                            srdm.setItemAlarmLevel(2);
                            srdm.setItemAlarmTime(tsm.getDtime().getTime());
                            srdm.setItemAlarmMessage("状态有告警");
                        }
                        else
                        {
                            srdm.setStatus(0);//0正常，1告警，2离线
                            srdm.setItemAlarmLevel(0);
                            srdm.setItemAlarmTime(tsm.getDtime().getTime());
                            srdm.setItemAlarmMessage("Thales运行状态运行正常");
                        }
                        result.setResultFlag(0);
                        result.setResult(srdm);
                        result.setResultErrorMsg("查询成功");
                    }
                    else
                    {
                        result.setResultFlag(-1);
                        result.setResultErrorMsg("查询结果为空");
                    }
                }
                else
                {
                    result.setResultFlag(-1);
                    result.setResultErrorMsg("查询结果为空");
                }
            }




        }
        return result;
    }


    public FieldDataModel getFieldAlarmByStrategyConfig(String itemKey,FieldDataModel fdm,List<AttributeToFieldModel> AttributeToFieldList)
    {
        if(fdm!=null&&AttributeToFieldList!=null) {
            fdm.setAlarmStatus(0);//0正常，1告警，2关机
            fdm.setAlarmMessage("正常");
            fdm.setAlarmLevel(0);//0表示无告警，1轻微，2一般，3严重
            for(int i=0;i<AttributeToFieldList.size();i++)
            {
                if(AttributeToFieldList.get(i).getAttributeName().equals(fdm.getFieldName()))
                {
                    // getFieldAlarmStrategyByItemKeyAndFieldName(itemKey,AttributeToFieldList.get(i).getFieldName());

                }
            }


        }
        return fdm;
    }
}
